<?php
/**
 * | @author 李鹏博^life <907215837@qq.com>
 * +----------------------------------------------------------------------
 * | @copyright 2019 - 2019 HQ
 * +----------------------------------------------------------------------
 * | @version $Id: 2019/5/17 12:11 wwwroot Member.php 韩威兵^life $
 * +----------------------------------------------------------------------
 */


namespace app\api\controller;

use think\Db;
use app\common\common\model\order\fromId;
use app\common\common\Server\commonServer;
use app\api\server\member\memberServer;


class Member extends Base
{


    /**
     * 添加formID接口
     */
    public function addUserNewFormId(){


        $key = input('post.key');
        $openId = input('post.open_id');
        $formId = input('post.form_id');
        if($formId == 'the formId is a mock one'){

            commonServer::error(2,[],$formId)->exits();
        }
        try{

            if(empty($key)|| empty($openId)|| empty($formId)){
                $err['k'] = $key;
                $err['o'] = $openId;
                $err['f'] = $formId;
                aw_log($err, 'form_id.log');
                commonServer::error(2)->exits();
            }
            $member_server = new memberServer();
            //验证key合法
            $member_info = $member_server->checkCiphertext($key);
            if($member_info === false){
                commonServer::$showMsg = '密钥不合法';
                commonServer::error(2, [],'密钥不合法')->exits();
            }

            $memberServer = new memberServer();
            $result = $memberServer->addUserNewFormId($member_info['id'],$openId,$formId);
            if($result === false){
                commonServer::error(99997,['未添加成功'])->exits();
            }
            commonServer::success($result, '添加formId成功')->exits();

        }catch (\Exception $e){
            $err = formatErr($e);
            commonServer::error(99997,[], $err)->exits();
        }
    }
}